<?php
/**
 * @author Minh Luan
 * @copyright 2012
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Đăng tin tuyển dụng</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style media="all" type="text/css">
@import "../css/all.css";
</style>
</head>
<body>
<div id="main">

    <?php
        $page = 3;
        include "../admin/header.php";  
        include "../service/userService.php";
        include "../service/recruitmentsService.php";
        include "../service/locationsService.php";
        include "../service/majorsService.php";
        include "../service/positionsService.php";
    ?>  
  <div id="middle">
    <div id="left-column">
      <h3>Header</h3>
      <ul class="nav">
        <?php
        //Company function
        if($loggedInUser[2] == 3){
            echo "<a href='../pc/recruitments.php'>Đăng tin tuyển dụng</a>";
        }
        ?>
      </ul>
       
      </div>
    <div id="center-column">
      <div class="top-bar">
        <h1>Thông tin tuyển dụng</h1>
      </div>
      <br />
      <?php
        $infor = null;
        $infor = mysql_fetch_array(getCompanyInfor($loggedInUser[1]));
        
        $degress = getDegrees();
        $locations = getLocations();
        $majors = getMajors();
        $positions = getPositions();
        
        if(isset($_GET["n"])){
        //Edit recruitment
            $id = $_GET["n"];
        $recruitment = mysql_fetch_array(getRecruitment($id));
      ?>
      <div class="table"><img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
      
      <form id="publishForm" action="../action/updateRecruitmentAction.php" method="POST">
        <table class="listing form" cellpadding="0" cellspacing="0">
          <tr>
            <td class="first" width="172">Tiêu đề</strong></td>
            <td class="last">
                <input name="title" id="title" type="text" class="text" name="title" id="title"  value="<?php echo $recruitment["RECRUITMENT_NAME"]; ?>"/>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"><strong>Ngành nghề</strong></td>
            <td class="last">
            <select name="major" id="major">
                <option value="0">Ngành nghề</option>
                <?php
                while($major = mysql_fetch_array($majors)){
                ?>
                <option <?php echo $major['MAJOR_ID'] == $recruitment['MAJOR_ID']?"selected=selected":""; ?> value="<?php echo $major["MAJOR_ID"]; ?>"><?php echo $major["MAJOR_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr>
            <td class="first"><strong>Vị trí</strong></td>
            <td class="last">
            <select name="position" id="position">
                <option value="0">Vị trí</option>
                <?php
                while($position = mysql_fetch_array($positions)){
                ?>
                <option <?php echo $position['POSITION_ID'] == $recruitment['POSITION_ID']?"selected=selected":""; ?> value="<?php echo $position["POSITION_ID"]; ?>"><?php echo $position["POSITION_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"><strong>Nơi làm việc</strong></td>
            <td class="last">
            <select name="location" id="location">
                <option value="0">Nơi làm việc</option>
                <?php
                while($location = mysql_fetch_array($locations)){
                ?>
                <option <?php echo $location["JOB_LOC_ID"] == $recruitment['JOB_LOC_ID']?"selected=selected":""; ?> value="<?php echo $location["JOB_LOC_ID"]; ?>"><?php echo $location["JOB_LOC_NAME"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr>
            <td class="first"><strong>Bằng cấp yêu cầu</strong></td>
            <td class="last">
            <select name="degree" id="degree"> 
                <option value="0">Bằng cấp yêu cầu</option>
                <?php
                while($degree = mysql_fetch_array($degress)){
                ?>
                <option <?php echo $degree["DEGREE_ID"] == $recruitment['DEGREE_ID']?"selected=selected":""; ?> value="<?php echo $degree["DEGREE_ID"]; ?>"><?php echo $degree["DEGREE_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"> Miêu tả công việc</td>
            <td class="last">
                <textarea name="description" id="description" style="width: 300px;"><?php echo $recruitment["RECRUITMENT_DESCRIPTION"]; ?></textarea>
            </td>
          </tr>
        </table>
        
        <input type="hidden" name="id" id="id" value="<?php echo $loggedInUser[0]; ?>" />
        <input type="hidden" name="type" id="type" value="<?php echo $loggedInUser[2]; ?>" />
        <input type="hidden" name="recruitmentId" id="recruitmentId" value="<?php echo $_GET["n"]; ?>" />
        </form>
        <div class="top-bar">
        <a href="#" class="button" onclick="document.forms['publishForm'].submit();">Cập nhật</a>
        </div>
        <p>&nbsp;</p>
      </div>
      <?php
      }else{
        //Create new Recruitment
      ?>
      <div class="table"><img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" /> <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
      
      <form id="publishForm" action="../action/addRecruitmentAction.php" method="POST">
        <table class="listing form" cellpadding="0" cellspacing="0">
          <tr>
            <th class="full" colspan="2">
            Tin tuyển dụng được đăng bởi: <?php echo $loggedInUser[1]; ?>
            </th>
          </tr>
          <tr>
            <td class="first" width="172">Tiêu đề</strong></td>
            <td class="last">
                <input type="text" class="text" name="title" id="title"  value=""/>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"><strong>Ngành nghề</strong></td>
            <td class="last">
            <select name="major" id="major">
                <option value="0">Ngành nghề</option>
                <?php
                while($major = mysql_fetch_array($majors)){
                ?>
                <option value="<?php echo $major["MAJOR_ID"]; ?>"><?php echo $major["MAJOR_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr>
            <td class="first"><strong>Vị trí</strong></td>
            <td class="last">
            <select name="position" id="position">
                <option value="0">Vị trí</option>
                <?php
                while($position = mysql_fetch_array($positions)){
                ?>
                <option value="<?php echo $position["POSITION_ID"]; ?>"><?php echo $position["POSITION_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"><strong>Nơi làm việc</strong></td>
            <td class="last">
            <select name="location" id="location">
                <option value="0">Nơi làm việc</option>
                <?php
                while($location = mysql_fetch_array($locations)){
                ?>
                <option value="<?php echo $location["JOB_LOC_ID"]; ?>"><?php echo $location["JOB_LOC_NAME"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr>
            <td class="first"><strong>Bằng cấp yêu cầu</strong></td>
            <td class="last">
            <select name="degree" id="degree">
                <option value="0">Bằng cấp yêu cầu</option>
                <?php
                while($degree = mysql_fetch_array($degress)){
                ?>
                <option value="<?php echo $degree["DEGREE_ID"]; ?>"><?php echo $degree["DEGREE_TITLE"]; ?></option>
                <?php
                }
                ?>
            </select>
            </td>
          </tr>
          <tr class="bg">
            <td class="first"> Miêu tả công việc</td>
            <td class="last">
                <textarea name="description" id="description"></textarea>
            </td>
          </tr>
        </table>
        
        <input type="hidden" name="id" id="id" value="<?php echo $loggedInUser[0]; ?>" />
        <input type="hidden" name="type" id="type" value="<?php echo $loggedInUser[2]; ?>" />
        </form>
        <div class="top-bar">
        <a href="#" class="button" onclick="document.forms['publishForm'].submit();">Đăng tin</a>
        </div>
        <p>&nbsp;</p>
      </div>
      <?php
      }
      ?>
      
      
    </div>
    <div id="right-column"> <strong class="h">Ghi chú</strong>
      <div class="box">Thay đổi cập nhật thông tin tuyển dụng</div>
    </div>
  </div>
  <?php include "../admin/footer.php";?>
</div>
</body>
</html>